package com.oocl.euc.core.maintenance.repository;

import com.oocl.euc.core.maintenance.model.FunctionAuth;
import com.oocl.euc.framework.base.persistence.IBaseRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface FunctionAuthRepository extends IBaseRepository<FunctionAuth, Long> {

    List<FunctionAuth> findByFunctionId(Long functionId);

    @Query(value = "SELECT * FROM PCRS_FUNCTION_AUTH WHERE FUNCTION_ID =?1 AND ROLE_ID IN ?2 AND REQUEST_STATUS_ID IN ?3", nativeQuery = true)
    List<FunctionAuth> findByFunctionIdAndRoleIdListAndStatusIdList(Long functionId, List<Long> roleIds, List<Long> statusIds);


    @Query(value = "SELECT * FROM PCRS_FUNCTION_AUTH WHERE FUNCTION_ID =?1 AND ROLE_ID IN ?2 AND REQUEST_STATUS_ID IS NULL", nativeQuery = true)
    List<FunctionAuth> findByFunctionIdAndRoleIdListWithoutStatusIdList(Long functionId, List<Long> roleIds);

    @Query(value = "SELECT * FROM PCRS_FUNCTION_AUTH WHERE FUNCTION_ID =?1 AND REQUEST_STATUS_ID IN ?2 AND REQUEST_STATUS_ID IS NULL", nativeQuery = true)
    List<FunctionAuth> findByFunctionIdAndStatusIdListWithoutRoleIdList(Long functionId, List<Long> statusIds);
}
